package com.weimei.conversionTreasure.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import com.chad.library.BR;
import com.google.android.material.tabs.TabLayout;
import com.weimei.conversionTreasure.R;
import com.weimei.conversionTreasure.app.AppViewModelFactory;
import com.weimei.conversionTreasure.databinding.ActivitySelKhBinding;
import com.weimei.conversionTreasure.viewModel.JyDetailVM;
import com.weimei.conversionTreasure.viewModel.SelKhVM;

import me.goldze.mvvmhabit.base.BaseActivity;

public class SelKhActivity extends BaseActivity<ActivitySelKhBinding, SelKhVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_sel_kh;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public SelKhVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, (ViewModelProvider.Factory) factory).get(SelKhVM.class);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);
        binding.khTab.addTab(binding.khTab.newTab().setText("经销商"));
        binding.khTab.addTab(binding.khTab.newTab().setText("客户"));
        binding.khTab.getTabAt(1).select();

        binding.khTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewModel.type.set(""+tab.getPosition());
                viewModel.onResume();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
}